package com.sbr.tbd.wicket.pages.administration.application;

import com.sbr.tbd.dao.ApplicationDao;
import com.sbr.tbd.model.Application;
import com.sbr.tbd.services.AdministrationService;
import com.sbr.tbd.wicket.pages.administration.AdministrationBasePage;
import com.sbr.tbd.wicket.panels.application.EditApplicationPanel;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.spring.injection.annot.SpringBean;


public class ListApplicationsPage extends AdministrationBasePage {

    @SpringBean
    private AdministrationService administrationService;


    @SpringBean
	private ApplicationDao applicationDao;
	
	
    public ListApplicationsPage() {
    	super();

    	add(new PropertyListView<Application>("applicationsList", applicationDao.readAll()) {

			@Override
			protected void populateItem(ListItem<Application> item) {
				final Application application = item.getModelObject();
				item.add(new Label("name", application.getName()));
				item.add(new Label("description", application.getDescription()));
                item.add(new Link<Application>("deleteLink") {
                    @Override
                    public void onClick() {
                        administrationService.delete(application);
                    }
                });
			}
    		
    	});
//    	add(new BookmarkablePageLink("addApplicationLink", AddApplication.class));
    	add(new EditApplicationPanel("editApplicationPanel"));
    }

    public void setApplicationDao(ApplicationDao applicationDao) {
		this.applicationDao = applicationDao;
	}

    public void setAdministrationService(AdministrationService administrationService) {
        this.administrationService = administrationService;
    }
}
